import { defineStore } from 'pinia'
import { useRouter } from "vue-router";

export const menuStore = defineStore('menus', {
    state: () => {
        return {
            tabsPage: [
                {
                    title: "主页",
                    name: "home",
                }
            ],
            TabsValue: ""
        };
    },
    getters: {
    },
    actions: {
        editableTabs(obj: any) {
            if (this.tabsPage.length !== 0) {
                var result = this.tabsPage.some(item=>item.name===obj.name)
                if (!result) {
                    this.tabsPage.push({ title: obj.title, name: obj.name });
                
                    this.TabsValue = obj.name;
                } else {
                    this.TabsValue = obj.name;
                }
            } else {
                this.tabsPage.push({
                    title: obj.title,
                    name: obj.name,
                });
                this.TabsValue = obj.name;
 
                const router = useRouter();
                router.push({ name: this.TabsValue });
            }
        },
        setTabsValue(str: string){
            this.TabsValue = str
        },
        settabsPage(list_menu: Array<any>){
            this.tabsPage = list_menu
        }
    }
})